package com.yoga.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.yoga.dao.MemberMapper;
import com.yoga.model.Member;
import com.yoga.model.search.MemberSearchBean;
import com.yoga.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yan
 * @date 2025/8/8
 */
@Service
public class MemberServiceImpl implements MemberService {

    private MemberMapper memberMapper;

    @Autowired
    public void setMemberMapper(MemberMapper memberMapper) {
        this.memberMapper = memberMapper;
    }


    @Override
    public Page<Member> findAll(Page<Member> page, MemberSearchBean msb) {
        return memberMapper.findAll(page, msb);
    }


    @Override
    public boolean add(Member member) {
        return memberMapper.insert(member) > 0;
    }

    @Override
    public boolean update(Member member) {
        return memberMapper.updateById(member) > 0;
    }

    @Override
    public List<Member> findAll() {
        return memberMapper.selectList(null);
    }

    @Override
    public int deletedByIds(List<Integer> ids, Integer deleted) {
        if (ids==null || ids.isEmpty()){
            return 0;
        }
        Member member = new Member();
        member.setDeleted(deleted);
        // 构造更新条件
        UpdateWrapper<Member> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("member_id", ids);

        return memberMapper.update(member, updateWrapper);
    }


}
